package com.briup.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DQLTest {
    public static void main(String[] args) throws Exception {
        var driver = "com.mysql.cj.jdbc.Driver";
        var url = "jdbc:mysql://192.168.179.11:3306/briup";
        var user = "root";
        var password = "root";

        Class.forName(driver);
        Connection conn = DriverManager.getConnection(url, user, password);
        Statement statement = conn.createStatement();
        String sql = "select * from t_user";
        ResultSet rs = statement.executeQuery(sql);
        while (rs.next()) {
            // 取每一个字段的值
            int id = rs.getInt("id");
            String name = rs.getString("name");
            int age = rs.getInt("age");
            System.out.println("编号："+id);
            System.out.println("姓名："+name);
            System.out.println("年龄："+age);
            System.out.println("----------");
        }
        statement.close();
        conn.close();
    }
}
